package drp.snowbell;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import drp.snowbell.cfg.Config;
import drp.snowbell.cfg.EntityConfig;
import drp.snowbell.exception.CatchException;


/**
 * 系统启动结束处理
 * 
 * @author wuhj
 * 
 */
public class Engine {
	private static Logger logger = Logger.getLogger(Engine.class);

	/**
	 * 启动.数据初始化
	 * 
	 * @return
	 */
	public synchronized static boolean start() {
		boolean ret = false;
		if (initializeConfig()) {

		}
		return ret;
	}

	/**
	 * 结束.数据清理和对线程池里的线程都发出停止命令
	 * 
	 * @return
	 */
	public synchronized static boolean shutdown() {
		boolean ret = false;
		return ret;
	}

	private static boolean initializeConfig() {
		boolean ret = false;
		try {
			if (Config.get() != null) {
				if (Config.getModuleConfig(Config.CORE_MODULE_NAME) != null) {
					ret = true;
				} else {
					logger.error("can't initialize system config");
				}
			} else {
				logger.error("can't initialize core module config");
			}
		} catch (Exception e) {
			CatchException.take(e);
		}
		return ret;
	}

	private static boolean initializeSystemModule() {
		boolean ret = false;

		Collection<EntityConfig> fileEclist = Config.getEntityConfigList(Config.CORE_MODULE_NAME);
		Map<String, EntityConfig> entityConfigMap = new HashMap<String, EntityConfig>();
		for (EntityConfig ec : fileEclist) {
			entityConfigMap.put(ec.getName(), ec);
		}

		// Collection<EntityConfig> annEcList

		// logger.error("can't initialize module config:" + moduleName);
		return ret;
	}
}
